package com.d3works.studio.db.repo;

import com.d3works.exception.D3worksException;
import com.d3works.studio.db.AppBuilder;
import com.d3works.studio.service.builder.AppBuilderService;
import com.google.inject.Inject;
import javax.validation.ValidationException;

public class AppBuilderRepo extends AppBuilderRepository {

  @Inject private AppBuilderService appBuilderService;

  @Override
  public AppBuilder save(AppBuilder appBuilder) {

    try {
      appBuilderService.build(appBuilder);
    } catch (D3worksException e) {
      throw new ValidationException(e);
    }

    return super.save(appBuilder);
  }

  @Override
  public void remove(AppBuilder appBuilder) {

    appBuilderService.clean(appBuilder);

    super.remove(appBuilder);
  }
}
